package com.marketlive.system.config.spring;

//import org.apache.commons.logging.Log;
//import org.apache.commons.logging.LogFactory;

/*
(C) Copyright MarketLive. 2006. All rights reserved.
MarketLive is a trademark of MarketLive, Inc.
Warning: This computer program is protected by copyright law and international treaties.
Unauthorized reproduction or distribution of this program, or any portion of it, may result
in severe civil and criminal penalties, and will be prosecuted to the maximum extent
possible under the law.
*/

import org.marketlive.system.config.IConfigurationManager;
import org.marketlive.system.config.IConfigurationBranch;
import org.marketlive.system.config.IConfigurationContext;

import java.util.ResourceBundle;

/**
 * 
 * @author Huw
 * 
 */
public class SpringConfigurationManager extends SpringPlaceholderConfigurer implements IConfigurationManager {

    /**
     * Sets the properties from the configuration manager.
     *
     * @param configurationRoot the path to the root directory for the configuration
     * @param ignoreList a comma-separated list of files and paths to ignore
     */
    public SpringConfigurationManager(String configurationRoot, String ignoreList) {
        super(configurationRoot,ignoreList);
    }

    /**
     * Sets the properties from the configuration manager.

     * @param configurationRoot the path to the root directory for the configuration
     */
    public SpringConfigurationManager(String configurationRoot) {
        this(configurationRoot,null);
    }

    /**
     * Sets the properties from the configuration manager.
     *
     */
    public SpringConfigurationManager() {
        super();
    }

    /**
     * Logger
     */
    //private static Log log = LogFactory.getLog(SpringConfigurationManager.class);

    /**
     * @inheritDoc
     */
    public boolean getAsBoolean(String name) {
        return getConfigurationManager().getAsBoolean(name);
    }

    /**
     * @inheritDoc
     */
    public boolean getAsBoolean(String name, boolean defaultValue) {
        try {
            return Boolean.parseBoolean(getAsString(name));
        } catch (IllegalArgumentException e) {
            return defaultValue;
        }
    }

    /**
     * @inheritDoc
     */
    public int getAsInt(String name) {
        return getConfigurationManager().getAsInt(name);
    }

    /**
     * @inheritDoc
     */
    public String getAsString(String name) {
        return getConfigurationManager().getAsString(name);
    }

    /**
     * @inheritDoc
     */
    public IConfigurationBranch getBranch(String path) {
        return getConfigurationManager().getBranch(path);
    }

    /**
     * @inheritDoc
     */
    public IConfigurationContext getContext() {
        return getConfigurationManager().getContext();
    }

    /**
     * @inheritDoc
     */
    public IConfigurationBranch getRoot() {
        return getConfigurationManager().getRoot();
    }

    /**
     * @inheritDoc
     */
    public void registerBundle(String path, ResourceBundle bundle) {
        getConfigurationManager().registerBundle(path,bundle);
    }

    /**
     * @inheritDoc
     */
    public String printConfiguration() {
        return getConfigurationManager().printConfiguration();
    }

    /**
     * @inheritDoc
     */
    public void init(String configurationRoot) {
        super.setConfigurationRoot(configurationRoot);
        super.init();
    }

    /**
     * @inheritDoc
     */
    public boolean isBranchDefined(String name) {
        return getConfigurationManager().isBranchDefined(name);
    }

    /**
     * @inheritDoc
     */
    public boolean isGoSecure(){
        return getConfigurationManager().isGoSecure();
    }    

}
